<div th:fragment="update-person" id="update-person" style="display: none">
    <div class="block-header">
        <div class="row">
            <div class="col-lg-7 col-md-6 col-sm-12">
                <h2>Update Person
                    <small class="text-muted">Welcome to Compass</small>
                </h2>
            </div>
            <div class="col-lg-5 col-md-6 col-sm-12">
                <ul class="breadcrumb float-md-right">
                    <li class="breadcrumb-item"><a  href="/hospital/index"><i class="zmdi zmdi-home"></i> Compass</a></li>
                    <li class="breadcrumb-item active"><a href="javascript:void(0);">Update Person</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="container-fluid">
        <div class="row clearfix">
            <div class="col-lg-12 col-md-12 col-sm-12">
                <div class="card">
                    <div class="header">
                        <h2><strong>Basic</strong> Information <small>更改信息</small> </h2>
                    </div>
                    <div class="body">
                        <div class="row clearfix">
                            <div class="col-sm-6">
                                <input type="hidden" value="" id="person_id">
                                <div class="form-group">
                                    <input type="password" class="form-control" id="person_password" placeholder="请输入密码">
                                </div>
                            </div>
                        </div>
                        <div class="row clearfix">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <input type="text" class="form-control" id="person_realname" placeholder="请输入姓名">
                                </div>
                            </div>
                        </div>
                             <input name="person_filename" id="person_filename" type="hidden" value=""/>
                            <div class="col-lg-12 col-md-12 col-sm-12">
                                <form action="/hospital/docotors/upload" id="person_frmFileUpload" class="dropzone" method="post" enctype="multipart/form-data">
                                    <div class="dz-message">
                                        <div class="drag-icon-cph"> <i class="material-icons">touch_app</i> </div>
                                        <h3>在这里可以重新上传图片</h3>
                                    </div>
                                    <div class="fallback">
                                        <input name="file" type="file" multiple />
                                    </div>
                                </form>
                            </div>

                        <div class="col-lg-12 col-md-12 col-sm-12">
                            <div class="card">
                                <div class="header">
                                    <h2><strong>原图片：</strong></h2>
                                </div>
                                <div class="body">
                                    <div id="person_image_show" class="list-unstyled row clearfix">

                                    </div>
                                </div>
                            </div>
                        </div>

                            <div class="col-sm-12">
                                <button onclick="updatePerson()" type="submit" class="btn btn-primary btn-round">提交</button>
                                <button type="button" class="btn btn-default btn-round btn-simple" href="/index/hospital">取消</button>
                            </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<script type="text/javascript">
    //更新个人信息
    function updatePerson() {
        var id= $("#person_id").val()
        var password = $("#person_password").val()
        var realname = $("#person_realname").val()
        var username = $("#p_user_username").val()
        var image = ''
        if ($("#person_filename").val() !== ""){
            image = $("#person_filename").val()
        }else {
            image = $("#person_image").attr('value')
            console.log(image)
        }
        if (typeof (password) == 'undefined' || typeof (realname) == 'undefined' || typeof (image) == 'undefined') {
            alert("请填写完整信息！")
            return
        }
        if ( password === null || realname === null || image === null) {
            alert("有未填写的信息！")
            return
        }
        $.ajax({
            url: "/hospital/doctors/updatePerson",
            type: "put",
            dataType: "json",
            data : JSON.stringify({
                id:id,
                username:username,
                password:password,
                realname:realname,
                image:image
            }),
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                if (data.code === 200){
                    document.getElementById ('photo').src=image;
                    if (image !== $("#person_image").attr("value")){
                        deleteUpload2($("#person_image").attr("value"))
                    }
                    $("#person_filename").attr('value',"")
                    window.location.href="/hospital/index";
                }else {
                    alert(data.message)
                    window.location.href="/hospital/index";
                }
            }
        })
    }
</script>
</div>